/**************************************************************************************************
* Title: SumMouse.cpp
* Author: Gael Huber
* Description: Handles mouse input and mouse events
**************************************************************************************************/
#include "SumMouse.h"

/**************************************************************************************************
* Default constructor
**************************************************************************************************/
Mouse::Mouse(void)
	: mouse(0)
{ }

/**************************************************************************************************
* Constructor with pointer to device used for input creation
**************************************************************************************************/
Mouse::Mouse(LPDIRECTINPUT8 input) 
	: mouse(0)
{
	// Create the mouse
	input->CreateDevice(GUID_SysMouse,
						&mouse,
						NULL);

	// Set the data format
	mouse->SetDataFormat(&c_dfDIMouse);

	// Set the control we have over the mouse
	mouse->SetCooperativeLevel(GetHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
}

/**************************************************************************************************
* Destructor
**************************************************************************************************/
Mouse::~Mouse(void) {
	if(mouse)	mouse->Unacquire();
}

/**************************************************************************************************
* Updates the mouse data
**************************************************************************************************/
void Mouse::update(void) {
	// Get access if we don't already have it
	mouse->Acquire();

	// Get input data
	mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID) &mouseState);
}

/**************************************************************************************************
* Returns the mouse state
**************************************************************************************************/
const DIMOUSESTATE& Mouse::getMouseState(void) const {
	return mouseState;
}